<template>
  <div class="outer">
    <h1>加入购物车的半场动画</h1>
    <button @click="isShow = !isShow">加入购物车</button>
    <transition
      name="one"
      @before-enter="oneBeforeEnter"
      @enter="oneEnter"
      @after-enter="oneAfterEnter"
    >
      <div class="text" v-show="isShow"></div>
    </transition>
  </div>
</template>

<script>
export default {
  name: "AddCart",
  data() {
    return {
      isShow: false,
    };
  },
  methods: {
    oneBeforeEnter(el) {
      el.style.transform = "translate(0,0)";
    },
    oneEnter(el, done) {
      el.offsetLeft;
      el.style.transform = "translate(340ox,300px)";
      el.style.transition = "all 1s linear";

      done();
    },
    //默认是动画执行完成才执行
    oneAfterEnter() {
      console.log("oneAfterEnter");
      this.isShow = !this.isShow;
    },
  },
};
</script>

<style scoped>
.text {
  width: 20px;
  height: 20px;
  background: red;
  border-radius: 50%;
}
.outer {
  height: 500px;
  width: 400px;
  border: 1px solid #000;
}
</style>